{% from "macros/forms.html" import form_input, form_select, form_textarea %}
{% from "macros/datatable.html" import datatable %}

{% set form_error = form_error | default({}) %}
{% set form_fields = form_fields | default({}) %}
<div class="bg-base-100 p-4">
  <h1 class="text-3xl font-bold mb-5 w-3/4 ml-[10%]">{{ submit_text }}</h1>

  <form id="{{ model_name }}-form"
        class="w-1/2 ml-[10%]"
        {{ form_action }}
        hx-swap="innerHTML"
        hx-target="#form-container"
        hx-target-error="#form-container">
    {% include "partials/admin_form_error.html" %}
    {% for field_name, field in form_fields.items() %}
      {% if field.type == 'text' or field.type == 'number' %}
        {{ form_input(field.label, field_name, field.value, form_error[field_name], type=field.type, required=field.required) }}
      {% elif field.type == 'textarea' %}
        {{ form_textarea(field.label, field_name, field.value, form_error[field_name], required=field.required) }}
      {% elif field.type == 'select' %}
        {{ form_select(label=field.label, name=field_name, value=field.value, options=field.options) }}
      {% elif field.type == 'switch' %}
        {{ form_switch(field.label, field_name, field.value, required=field.required) }}
      {% endif %}
    {% endfor %}

    <input type="submit" class="btn btn-primary w-1/2" value="{{ submit_text }}" />
  </form>
</div>
